package com.restaurant.application.root.commonui.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class CellData implements PickableBean {

    public static final String FN_VALUE = "value";
    public static final String FN_CLICKPATH = "clickPath";
    public static final String FN_DOUBLECLICKPATH = "doubleClickPath";
    public static final String FN_STATECLASS = "stateClass";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_VALUE,
            FN_CLICKPATH,
            FN_DOUBLECLICKPATH,
            FN_STATECLASS);

    private String value;
    private String clickPath;
    private String doubleClickPath;
    private String stateClass;

    public CellData(String value, String clickPath, String doubleClickPath, String stateClass) {
        setValue(value);
        setClickPath(clickPath);
        setDoubleClickPath(doubleClickPath);
        setStateClass(stateClass);
    }

    public CellData() {
    }

    public CellData duplicate() {
        CellData result = new CellData();
        result.value = this.value;
        result.clickPath = this.clickPath;
        result.doubleClickPath = this.doubleClickPath;
        result.stateClass = this.stateClass;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public CellData withValue(String value) {
        setValue(value);
        return this;
    }

    public CellData withValue(String value, String defaultValue) {
        setValue(value == null ? defaultValue : value);
        return this;
    }

    public String getClickPath() {
        return clickPath;
    }

    public void setClickPath(String value) {
        this.clickPath = value;
    }

    public CellData withClickPath(String value) {
        setClickPath(value);
        return this;
    }

    public CellData withClickPath(String value, String defaultValue) {
        setClickPath(value == null ? defaultValue : value);
        return this;
    }

    public String getDoubleClickPath() {
        return doubleClickPath;
    }

    public void setDoubleClickPath(String value) {
        this.doubleClickPath = value;
    }

    public CellData withDoubleClickPath(String value) {
        setDoubleClickPath(value);
        return this;
    }

    public CellData withDoubleClickPath(String value, String defaultValue) {
        setDoubleClickPath(value == null ? defaultValue : value);
        return this;
    }

    public String getStateClass() {
        return stateClass;
    }

    public void setStateClass(String value) {
        this.stateClass = value;
    }

    public CellData withStateClass(String value) {
        setStateClass(value);
        return this;
    }

    public CellData withStateClass(String value, String defaultValue) {
        setStateClass(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "value":
                return getValue();
            case "clickPath":
                return getClickPath();
            case "doubleClickPath":
                return getDoubleClickPath();
            case "stateClass":
                return getStateClass();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof CellData)) return false;
        return signature().equals(((CellData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean CellData has no signature defined, no hash code or equals possible.");
    }
}
